Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite findTargets for better performance. #11754

Merged
merged 2 commits into from
Jul 10, 2023

Conversation

asvitkine
Copy link
Contributor

Change Summary & Additional Notes

  • Avoids O(n^2) destroyer checks.
  • Avoids an expensive removeAll() call.
  • Uses a single stream filter to process, removing an unnecessary intermediate collection in the common case when no destroyers are present.

Note: This was showing up in performance profiles.

Release Note

- Avoids O(n^2) destroyer checks.
- Avoids an expensive removeAll() call.
- Uses a single stream filter to process, removing an unnecessary intermediate collection in the common case when no destroyers are present.

Note: This was showing up in performance profiles.
@asvitkine asvitkine merged commit 31b69a6 into triplea-game:master Jul 10, 2023
1 check passed
.collect(Collectors.toSet());
UnitType unitType, boolean destroyerPresent, Set<UnitType> enemyUnitTypes) {
Set<UnitType> cannotTarget = unitType.getUnitAttachment().getCanNotTarget();
// Note: uses a single stream instead of a sequence of removeAll() calls for performance.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment will be confusing to those not looking at this diff! =D
(Arguably this is something for the commit history)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants